package DieSiedler;
/*
 * Main.java
 *
 * Created on 9. Mai 2007, 09:49
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

/**
 * Wurde verwendet um Controller zu testen
 * @author oliver
 */
public class StartController {
    
    /** Creates a new instance of Main */
   
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        try{
            if(args.length<1){
                System.out.println("Argument = host");
            }else{
                 System.out.println("Host:"+args[0]);   
                 Controller controller = new Controller(args[0]);
                 VirtualPlayerController vp = new VirtualPlayerController();
                 vp.add(controller);
                 InformationController info = new InformationController();
                 controller.add(info);
                 controller.add(vp);
                 int playerID1=vp.spielerAnmelden();
                 String msg;
                 System.out.println("Your playerID is: "+playerID1+" (specially created for you!)");
                 System.out.println("Nachricht eingeben:");
                 while(true){
                     
                     try{
                        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                        msg = new String (in.readLine());
                        System.out.print("sende Nachricht...");
                        controller.sendeChatMessage(playerID1,new ChatMessage(msg, MessageTyp.Information, playerID1));
                        
                        System.out.println("OK");
                     }
                     catch(Exception e){System.out.print("[ERROR] Kernschmelze, system wird beendet"); System.exit(-1);}	

                 }

            }
           
         
        }catch(Exception e){
              e.printStackTrace();
        }
         
   }
    
}
